<template>
  <div class="chooseLoca">
    <div class="location">
      <!-- 头部 -->
      <p>
        定位城市
        <i class="el-icon-s-home" @click="back"></i>
      </p>
      <span>定位失败请选择城市</span>
    </div>
    <!-- 城市选择 -->
    <ul>
      <div v-for="(item,index) in prefix" :key="index">
        <li class="title" v-if="item=='hot'">热门城市</li>
        <li class="title" v-else>{{item}}</li>
        <li v-for="(city, index) in citys" :key="index" v-show="item==city.Initials">
          <span @click="changeCity(city.name)">{{city.name}}</span>
        </li>
      </div>
    </ul>
  </div>
</template>

<script>
export default {
  data: function () {
    return {
      citys: [],
      tiao: true,
      isShow: false,
      prefix: [
       
      ],
    };
  },
  mounted() {
    // 获取城市
    this.axios.get("/location").then((res) => {
      this.citys = res.data.result;
      this.citys.forEach(ele=>{
        this.prefix.push(ele.Initials)
      })
      this.prefix=Array.from(new Set(this.prefix))
    });
  },
  methods: {
    changeCity(value) {
      this.$store.commit("city", value);
      if (window.location.href == "http://localhost:8080/#/category") {
        this.$store.commit("cityShow");
      } else {
        location.href = "#/";
      }
    },
    back() {
      location.href = "#/";
    },
  },
};
</script>
<style scoped>
/* 顶部样式 */
.chooseLoca div {
  display: block;
  margin-bottom: 5px;
}
.chooseLoca p {
  display: block;
  background-color: #f5f5f5;
  text-align: left;
  padding: 5px 10px 5px 20px;
  overflow: hidden;
}
/* 头部样式 */
.chooseLoca .location {
  overflow: hidden;
}
.chooseLoca .location p i {
  color: #777;
  float: right;
  font-size: 22px;
  margin-right: 5px;
}
.chooseLoca .location span {
  border: 1px solid #e7e7e7;
  float: left;
  margin-left: 30px;
  border-radius: 5px;
  padding: 10px 35px 10px 35px;
  margin-top: 10px;
}
/* 城市选择的样式 */
.chooseLoca ul {
  list-style: none;
  overflow: scroll;
  padding-left: 15px;
  height: 400px;
}
.chooseLoca ul .title {
  width: calc(100vw - 37px);
  text-align: left;
  padding-left: 10px;
  background-color: #ddd;
  height: 20px;
  line-height: 24px;
}
.chooseLoca ul li {
  float: left;
  margin: 15px 0;
  width: 150px;
}
/* 城市选择按钮样式 */
.chooseLoca ul li span {
  border: 1px solid #e7e7e7;
  border-radius: 5px;
  padding: 10px 30px 10px 30px;
}
</style>

